package com.jiangjun.fetch.quartz;

import java.util.TimerTask;

import EDU.oswego.cs.dl.util.concurrent.FutureResult;

import com.jiangjun.fetch.Weibo;
import com.jiangjun.fetch.mongo.MongoDBSupport;
import com.jiangjun.fetch.threadpool.FetchWeiboHandleCallable;
import com.jiangjun.fetch.threadpool.FetchWeiboThreadPool;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;

public class FetchWeiboTask extends TimerTask {

	@Override
	public void run() {
		// TODO Auto-generated method stub
		MongoDBSupport mongoDBSupport = MongoDBSupport.getInstance();
		BasicDBObject param = new BasicDBObject();
		param.put("isEnable", "1");
		DBCursor cursor = mongoDBSupport.queryCollection(
				MongoDBSupport._WEIBO, param);
		while (cursor.hasNext()) {
			DBObject object = cursor.next();
			System.out.println(object.toString());
			Weibo weibo = new Weibo();
			weibo.setId(object.get("id").toString());
			weibo.setName(object.get("name").toString());
			try {
				FetchWeiboThreadPool.execute(new FutureResult()
						.setter(new FetchWeiboHandleCallable(weibo)));
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
